package com.hzp.lolnews.ui.news.presenter;

import android.util.Log;

import com.hzp.lolnews.base.IBasePresenter;
import com.hzp.lolnews.bean.HomeContent;
import com.hzp.lolnews.bean.HomeGrid;
import com.hzp.lolnews.bean.HomeRow;
import com.hzp.lolnews.ui.news.model.INewsContentImpl;
import com.hzp.lolnews.ui.news.model.OnLoadHomeListListener;
import com.hzp.lolnews.ui.news.model.OnLoadMoreListener;
import com.hzp.lolnews.ui.news.model.OnRefreshListener;
import com.hzp.lolnews.ui.news.view.IHomeContent;

import java.util.List;

/**
 * Created by Administrator on 2016/10/19 0019.
 */
public class HomePresenter implements IBasePresenter {
    private INewsContentImpl news;
    private IHomeContent homeRowView;

    public HomePresenter(IHomeContent view){
        news = new INewsContentImpl();
        this.homeRowView = view;
    }

    public void loadData(){
       news.loadFounds(homeRowView.getPath(), new OnLoadHomeListListener() {
           @Override
           public void onSuccessHomeRow(List<HomeRow> list) {
               homeRowView.addHomeRow(list);
           }

           @Override
           public void onSuccessHomeGrid(List<HomeGrid> list) {
                homeRowView.addHomeGrid(list);
           }

           @Override
           public void onSuccessHomeContent(List<HomeContent> list) {
                homeRowView.addHomeContent(list);
           }
           @Override
           public void onFailure(String msg, Throwable e) {
               homeRowView.showLoadFailMsg(msg, e);
               Log.i("TAG", "onFailure:============================== " + msg);
           }
       });
    }

    public void onReFresh(){
        news.onRefresh(homeRowView.getRefresh(), new OnRefreshListener() {
            @Override
            public void onRefresh(List<HomeContent> list) {
                homeRowView.addRefresh(list);
            }

            @Override
            public void onFailure(String msg, Throwable e) {
                homeRowView.showLoadFailMsg(msg, e);
            }
        });
    }

    public void onLoadMore(){
        news.onLoadMore(homeRowView.getLoadMore(), new OnLoadMoreListener() {
            @Override
            public void onLoadMore(List<HomeContent> list) {
                homeRowView.addLoadMore(list);
            }

            @Override
            public void onFailure(String msg, Throwable e) {
                homeRowView.showLoadFailMsg(msg, e);
            }
        });
    }
}
